<%--
  Created by IntelliJ IDEA.
  User: CVV
  Date: 2018/6/26
  Time: 17:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>手动调度 - 物流管理系统</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <style media="all" type="text/css">
        @import "../../style/all.css";
        @import "../../style/jquery/ui.all.css";
    </style>
    <style>
        .black_overlay {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.8;
            opacity: .80;
            filter: alpha(opacity=88);
        }

        .white_content {
            display: none;
            position: absolute;
            top: 25%;
            left: 25%;
            width: 30%;
            height: 20%;
            padding: 20px;
            border: 10px solid orange;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }
    </style>
    <script type="text/javascript" src="../../script/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="../../script/jquery-ui-personalized-1.6rc6.min.js"></script>
    <script type="text/javascript" src="../../script/date.js"></script>
    <script type="text/javascript" src='../../script/common.js'></script>
    <script type="text/javascript">
        var orderid = null;
        function hideDiv() {
            document.getElementById('light').style.display = 'none';
            document.getElementById('fade').style.display = 'none';
        }

        function getDiv() {
            document.getElementById('light').style.display = 'block';
            document.getElementById('fade').style.display = 'block';
        }

        $(function () {
            $.ajax({
                type: "get",
                url: "/stapi/selectAll",
                success(res) {

                    var json = eval(res);
                    $.each(json, function (index, item) {
                        $("#dispatchselect").append('<option>' + json[index].stationName + '</option>');
                    })
                },
                error(res) {
                    alert("响应失败，请稍后再试1");
                }

            })
            $("#cancel").live("click", function () {
                hideDiv();
            })
            $('.dispatch').live("click", function () {
                var value = $(this).parent().parent().find(".ORDERSTATE").text();
                if (value == "缺货") {
                    alert("此订单缺货，请选择其他订单调度");
                }
                else {
                    orderid = $(this).parent().parent().find(".ORDERID").text();
                    getDiv();
                }
            })
            $("#submit").live("click", function () {
                var station = $("#dispatchselect").val();
                $.ajax({
                    type: "post",
                    url: "/orderapi/update",
                    data: {"station": station, "orderId": orderid},
                    success(res) {
                        alert(res)
                    },
                    error(res) {
                        alert("响应失败，请稍后再试2");
                    }
                })
                $.ajax({
                    type: "post",
                    url: "/lorder/update",
                    data: {"deliversubstation": station, "orderid": orderid},
                    success(res) {
                    },
                    error(res) {
                        alert("响应失败，请稍后再试3");
                    }
                })
               hideDiv();
            })
        })
        var divContent = " <tr class=\"bg\">\n" +
            "                <td class=\"ORDERID\"></td>\n" +
            "                <td class=\"CUSTOMER\"></td>\n" +
            "                <td class=\"ORDERDATE\"></td>\n" +
            "                <td class=\"REQUIREDDATE\"></td>\n" +
            "                <td class=\"ORDERTYPE\"></td>\n" +
            "                <td class=\"ORDERSTATE\"></td>\n" +
            "                <td class=\"ADDRESS\"></td>\n" +
            "                <td id='td-list'>\n" +
            "                    <input class='dispatch' type='button' name='' value='调度'>\n" +
            "                    <a class='detail'><img  title=\"订单详情\" src=\"../../style/img/detail-ico.png\"/></a>\n" +
            "                </td>\n" +
            "            </tr>"

        function clearDiv(length, json) {
            for (var k = 1; k < length; k++) {
                $(".bg").eq(1).remove();
            }
            for (var k = 0; k < json.length; k++) {
                $(".bg").eq(0).after(divContent)
            }
        }

        function checkType(s) {
            if (s == "1")
                return "新订";
            else if (s == "2")
                return "换货";
            else if (s == "3")
                return "退货";
            else if (s == "4")
                return "退订";
            else if (s == "5")
                return "货到付款";
            else if (s == "6") ;
            return "上门收费";
        }

        function addDiv(json) {
            $.each(json, function (index, item) {
                json[index].ordertype = checkType(json[index].ordertype);
                $(".bg").eq(index + 1).find(".ORDERID").append(json[index].orderid);
                $(".bg").eq(index + 1).find(".CUSTOMER").append(json[index].lcustomer.customername);
                $(".bg").eq(index + 1).find(".ORDERDATE").append(json[index].orderdate);
                $(".bg").eq(index + 1).find(".REQUIREDDATE").append(json[index].requireddate);
                $(".bg").eq(index + 1).find(".ORDERTYPE").append(json[index].ordertype);
                $(".bg").eq(index + 1).find(".ORDERSTATE").append(json[index].orderstate);
                $(".bg").eq(index + 1).find(".ADDRESS").append(json[index].address);
                $(".bg").eq(index + 1).find(".detail").attr("href","http://localhost:8080/sch_hub/order/linkman.jsp?id="+json[index].orderid);
            })
        }

        $(function () {
            $.ajax({
                type: "get",
                url: "/lorder/selectAllFour",
                success(res) {
                    var json = eval(res);
                    $("#counter").text(json.length);
                    var length = $(".bg").length;
                    clearDiv(length, json);
                    addDiv(json);
                },
                error(res) {
                    alert("响应失败，请稍后再试")
                }
            })
            $("#select").click(function () {
                var start = $("#start").val();
                var end = $("#end").val();
                var choice = $("#choice").val();
                $.ajax({
                    type: "get",
                    url: "/lorder/select",
                    data: {"start": start, "end": end, "choice": choice},
                    success(res) {
                        var json = eval(res);
                        $("#counter").text(json.length);
                        var length = $(".bg").length;
                        clearDiv(length, json);
                        addDiv(json);
                    },
                    error(res) {
                        alert("响应失败，请稍后再试")
                    }
                })
            })
            datepicker('.date-two');
        });
    </script>
</head>
<body style="background: none">
<div class="top-bar">
    <h1>手动调度</h1>
    <div class="breadcrumbs">
        <div class="button-bar">
            <input type="button" name="Submit" value="帮助" class="button" onclick="help('物流管理系统')"/>
            <input type="button" id="select" name="Submit" value="查询" class="button"/>
        </div>
        <a href="../../index.jsp" target="_top">首页</a> /
        <a href="../index.jsp" target="_top">调度中心</a>
    </div>
</div>
<div class="select-bar">
    <table class="select-table">
        <tr>
            <th>期望投递日期</th>
            <td style="white-space:nowrap"><input id="start" type='text' style='width:75px' class="date-two text"
                                                  name='start'
                                                  readonly/>to<input type='text' style='width:75px' id="end"
                                                                     class="date-two text" name='end' readonly/></td>
            <th>订单类型</th>
            <td>
                <select id="choice" style='width:auto'>
                    <option>全部</option>
                    <option>新订</option>
                    <option>换货</option>
                    <option>退货</option>
                    <option>退订</option>
                    <option>货到付款</option>
                    <option>上门收费</option>
                </select></td>
        </tr>
    </table>
</div>

<div class="table">
    <img src="../../style/img/bg-th-left.gif" width="8" height="7" alt="" class="left"/>
    <img src="../../style/img/bg-th-right.gif" width="7" height="7" alt="" class="right"/>
    <form action='' method='post' name='formTable'>
        <table class="listing" cellpadding="0" cellspacing="0">
            <tr class="bg">
                <th class="first">订单号</th>
                <th>客户</th>
                <th>订单产生日期</th>
                <th>期望投递日期</th>
                <th>订单类型</th>
                <th>订单状态</th>
                <th>投递地址</th>
                <th class="last">操作</th>
            </tr>
        </table>
    </form>
    <div class='pager'>
        共<a id="counter"></a>条记录 每页10条
        第1页/共1页
        <a href="#">第一页</a>
        <a href="#">上一页</a>
        <a href="#">下一页</a>
        <a href="#">最后一页</a>
        转到<input type="text" class="text" size="1" value="1"/>页
        <input type="button" class="button" onclick="" value="GO"/>
    </div>
</div>

<div id="light" class="white_content">
    <p>请选择需要调度的站点：</p>
    <select id="dispatchselect">
    </select>
    <input id="submit" type="button" value="确认">
    <input id="cancel" type="button" value="取消">
</div>
<div id="fade" class="black_overlay">
</div>
</body>
</html>
